package com.bit.deom.controller;

import com.bit.deom.model.MessageInfo;
import com.bit.deom.service.MessageInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private MessageInfoService messageInfoService;

    @RequestMapping("/getList")
    public List<MessageInfo> getList() {
        return messageInfoService.queryAll();
    }

    @RequestMapping("/addMessage")
    public boolean addMessage(MessageInfo messageInfo) {
        System.out.println(messageInfo);
        if (   !StringUtils.hasLength(messageInfo.getFrom())
            || !StringUtils.hasLength(messageInfo.getTo())
            || !StringUtils.hasLength(messageInfo.getMessage())
        )  {
            return false;
        }
        messageInfoService.addMessage(messageInfo);
        return true;
    }
}
